package Connect;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import org.jdom.*;
import org.jdom.input.SAXBuilder;

//stabileste o conexiune cu serverul Web
public class Connection {
	
	public static Document connect(String server){
		Document response = null;
		
		try{
			URL u = new URL(server);
			URLConnection uc = u.openConnection();
			HttpURLConnection connection = (HttpURLConnection) uc;
			
			connection.setDoOutput(true);
			connection.setDoInput(true);
			connection.setRequestMethod("GET");

			InputStream in = connection.getInputStream();

			SAXBuilder parser = new SAXBuilder();
			response = parser.build(in);
			in.close();
			connection.disconnect();
		} catch(Exception e){
			//System.err.println(e);
			//e.printStackTrace();
			e.printStackTrace();
		}
		
		return response;
	}

}